const KoaRouter = require('koa-router')
const HttpClient = require('../util/HttpClient')
const Template = require('../util/Template')

const router = new KoaRouter();
const modules = require('../../modules');

router.get('/portal/getDoorRenovation', async ctx => {
  let script = ['/portal.setting.js']
  let modConfig = modules['portal.setting']
  let reqHeaders = ctx.request.headers
  let result = await HttpClient.request('/setting/superQrcode', 'get', null, {
    headers: reqHeaders
  })
  let body = result.body
  
  ctx.body = await Template.renderWithHtml('门户页面设置', body, script, modConfig.template, ctx)
})

router.get('/portal', async ctx => {
  let script = ['/portal.js']
  let modConfig = modules['portal']
  let reqHeaders = ctx.request.headers
  let result = await HttpClient.request('/setting/superQrcode', 'get', null, {
    headers: reqHeaders
  })
  let body = result.body
  
  ctx.body = await Template.renderWithHtml('门户主页', body, script, modConfig.template, ctx)
})

router.get('/portal/getDoorConfigPage', async ctx => {
  let script = ['/portal.config.js']
  let modConfig = modules['portal.config']
  let reqHeaders = ctx.request.headers
  let result = await HttpClient.request('/setting/superQrcode', 'get', null, {
    headers: reqHeaders
  })
  let body = result.body
  
  ctx.body = await Template.renderWithHtml('门户配置', body, script, modConfig.template, ctx)
})

module.exports = router;
